Skip to content

fix: update Python SDK schemas for UCP release 2026-01-23#21

Merged
damaz91 merged 45 commits intoUniversal-Commerce-Protocol:mainfrom
cusell-google:fix-2026-01-23-update
Mar 26, 2026
Merged

fix: update Python SDK schemas for UCP release 2026-01-23#21
damaz91 merged 45 commits intoUniversal-Commerce-Protocol:mainfrom
cusell-google:fix-2026-01-23-update

Conversation

@cusell-google
Copy link
Contributor

@cusell-google cusell-google commented Mar 24, 2026

Overview

The python-sdk was previously stuck on the older 2026-01-11 release. This Pull Request updates the SDK tooling and regenerates the Pydantic models to ensure full compatibility with the (currently latest) Universal Commerce Protocol release: UCP 2026-01-23 Specification.

Detailed Changes

Documentation & Developer Experience

  • README: Fixed setup instructions to clarify the correct directory navigation during environment bootstrapping.
  • Code Generation Safety: Simplified the ruff format output pipeline inside generate_models.sh to prevent masking terminal lint failures with silent grep fallback logic.

Schema Pre-Processor Architecture (preprocess_schemas.py)

This PR significantly rewrites the schema pre-processor logic to improve maintainability and generate safer representations used by datamodel-codegen. Key updates include:

  • Decoupling the Monolith: Split the massive merge_all_of_to_node function into modular helper functions (_process_all_of_item, _apply_merged_state) reducing unsafe variable mutations and nested conditions.
  • Purer Side-effects: Rewrote fix_metadata_structure into a purely functional normalize_metadata_schemas which performs mutations exclusively in memory instead of committing midway disk writes.
  • Safer Polymorphic Types: Flattening entity variants now correctly throws a ValueError rather than silently swallowing issues if entity_definition mappings are inadvertently empty.
  • Operation Variants Expansion: Re-factored the generate_variants routine by splitting out operation iterations (e.g., create vs update) into _create_single_variant builders.

Lints & Formats

  • ruff Compliance Fixes: Resolved Python stylistic debt surfaced by pre-commit, including fixing trailing whitespace limits, adjusting EOF sequences, and converting open() calls to Path().open(encoding="utf-8") (PTH123). Also removed built-in print tracing points with generic I/O stream writes (sys.stdout/sys.stderr) to comply with code-quality metrics.
  • Clean Model Inheritance: As a result of the schema property metadata normalizer (ucp_prop), Pydantic models like PlatformSchema, BusinessSchema, and ResponseCheckoutSchema finally generate correctly to extend Base classes natively rather than rendering as disconnected blobs.

damaz91 and others added 30 commits February 6, 2026 10:10
Change-Id: I7400c7bd870e3505d5b8c9a9e179d305c65bb3dc
Change-Id: I4583f94619b072eb7aff0fc28f040d0b2fd30de3
Change-Id: Ib7d74192095677f98a79906f5ed2d69dc16e1520
Change-Id: I2e70bdaf468ef7663b6c8e7542f2acf822d9df06
Change-Id: Id33ccc029b86af2486c82dc85d8bb12b3c55c680
Change-Id: Ia518ec52de6906da7262f7a76704a676a6318c40
Change-Id: I113bf00366152f552140a0f6410f738813c44007
Change-Id: I8413a4ad2e3886df6684ff7f654faa2ed2a95043
Change-Id: I63be54dcfc253861c05a9143483fd73a98f2c232
Change-Id: If59a9d92e40d71bc9d69d171b7020310ee9e26a1
Change-Id: I79bccca52f3a1d9d721c6a6f10d128f544411840
Change-Id: I0ac8995f2d15caa97ce57e9a1be574f012d5b9f2
* update SDK to 2026-01-23

* add init at the base level

* update README

* add request specific classes

* fix schema generation

* fix schema generation

* Update pyproject.toml

* update pre-processing to correctly handle self-reference

* fix

* sync

* address comments

Change-Id: I7400c7bd870e3505d5b8c9a9e179d305c65bb3dc

* add win32 specific check for paths

Change-Id: I4583f94619b072eb7aff0fc28f040d0b2fd30de3

* remove preprocessing

Change-Id: Ib7d74192095677f98a79906f5ed2d69dc16e1520

* update readme

Change-Id: I2e70bdaf468ef7663b6c8e7542f2acf822d9df06

* re-run of generate_models.sh

Change-Id: Id33ccc029b86af2486c82dc85d8bb12b3c55c680

* move ruff config

Change-Id: Ia518ec52de6906da7262f7a76704a676a6318c40

* delete temp files

Change-Id: I113bf00366152f552140a0f6410f738813c44007

* add LICENSE reference

Change-Id: I8413a4ad2e3886df6684ff7f654faa2ed2a95043

* add preprocessing to handle request type class generation

Change-Id: I63be54dcfc253861c05a9143483fd73a98f2c232

* change naming convention

Change-Id: If59a9d92e40d71bc9d69d171b7020310ee9e26a1

* update preprocessing to include more request types

Change-Id: I79bccca52f3a1d9d721c6a6f10d128f544411840

* delete ucp

Change-Id: I0ac8995f2d15caa97ce57e9a1be574f012d5b9f2
Change-Id: I50829c0f09a4e05bfcbd7ec53286a63f09e28cea
Change-Id: I769a18ba3fe14325911c4194da12f3f97ece46ea
Change-Id: Ie9d5ab50422b82efbf558cdd179ed3485cfde60f
Change-Id: I6d267035aa48aa5460c31a3764eab5a460026510
Change-Id: Ie4dd0293179c4387863dd4e66f51dde8443dd9b3
damaz91 and others added 11 commits March 3, 2026 10:06
Change-Id: I07006baf7aa7cd08b2ab723589b9373379e03d31
Change-Id: I66ced7ef4174da92816eb6cb50338a55ea68f67a
Change-Id: I5b8706c16740edca1b1c3a2b72ea5125b34ae0b5
Change-Id: Ia8d329b4b737a45a2a05fab59fc4c9e3c2a52efe
Change-Id: Ib54ea5de5be7ff65cf06ff14d0f90cd328636f6c
Change-Id: Id43fd21393ce74d863eca3407a967bb1d01e950d
Change-Id: Ia88b6b2c128a57a4499e3eb0fa5437ddbaaf535a
Change-Id: I2dc40c7312c2dd22fc3d03d426b7c5359938611c
Change-Id: I438b93b4adb693018f43428bf8e658bb5809ab74
Change-Id: I7112ad7d531eee33ea48de1c2871b0b92afe5e02
- Break monolithic `merge_all_of_to_node` down into smaller helper functions.
- Simplify `generate_variants` by extracting single variant creation logic.
- Introduce explicit ValueError when `entity_definition` is missing from `ucp.json`.
- Refactor `fix_metadata_structure` into a purely functional `normalize_metadata_schemas`.
- Addressed comments on PR 16.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the Universal Commerce Protocol (UCP) Python SDK's schema generation process. It introduces a robust preprocessing step that normalizes complex JSON schemas, flattens inheritance, and creates operation-specific model variants, resulting in a more streamlined and maintainable codebase. The changes also update the model generation script to support versioning and align project configurations with modern Python development standards.

Highlights

  • Enhanced Schema Generation Logic: Introduced a new Python script, preprocess_schemas.py, to perform advanced normalization and flattening of JSON schemas before model generation. This script handles allOf merging, distributes properties to anyOf/oneOf branches, and flattens entity references, leading to cleaner and more Pydantic-friendly models.
  • Versioned Schema Generation: The generate_models.sh script now supports specifying a UCP specification version, allowing for targeted model generation from different branches or releases of the UCP repository.
  • Model File Restructuring and Renaming: A significant refactoring of the generated model files has occurred, including renaming many *_req.py and *_resp.py files to more generic names (e.g., *_create_request.py, *.py) and reorganizing directories to better reflect the schema structure.
  • Pydantic V2 Compatibility: Added a new Jinja2 template specifically for generating Pydantic V2 RootModel classes, ensuring compatibility with the latest version of Pydantic.
  • Updated Project Configuration: The pyproject.toml file has been updated with a new project version, an additional author, and adjusted Ruff linting rules, including a change in indent width and ignoring specific docstring conventions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new schema preprocessing script (preprocess_schemas.py) and refactors the model generation workflow. Key changes include updates to generate_models.sh for improved UCP repository cloning, schema preprocessing, and post-generation formatting with ruff. The README.md installation instructions have been simplified, and pyproject.toml has been updated to reflect new ruff configurations and project metadata. Numerous generated model files have been updated or removed to align with the new schema processing and Pydantic v2 compatibility. Review feedback suggests addressing a potential error masking issue in the generate_models.sh script's ruff check command, clarifying installation instructions in README.md, and explicitly specifying UTF-8 encoding in preprocess_schemas.py for JSON file operations to enhance robustness.

- Run pre-commit to fix trailing whitespaces and formatting.
- Replace bare print statements in preprocess script with sys logging to fix ruff T201.
@cusell-google cusell-google force-pushed the fix-2026-01-23-update branch from 4195ab7 to 4825532 Compare March 24, 2026 14:55
- Pass exit codes during code generation by removing masked error trap.
- Fix README.md instructions for navigating before setup.
- Add explicit utf-8 encodings when opening JSON files.
@cusell-google cusell-google changed the title refactor(schemas): update schemas for 2026-01-23 fix: update Python SDK schemas for UCP release 2026-01-23 Mar 25, 2026
@cusell-google cusell-google marked this pull request as ready for review March 25, 2026 13:16
@cusell-google cusell-google requested review from a team as code owners March 25, 2026 13:16
@damaz91 damaz91 merged commit cbf9c9a into Universal-Commerce-Protocol:main Mar 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants